package com.kai.steering.data.service.service.impl;

import com.kai.steering.common.web.service.impl.BaseServiceImpl;
import com.kai.steering.common.web.vo.ReturnCodeExt;
import com.kai.steering.data.service.entity.domainObject.AnswerDO;
import com.kai.steering.data.service.entity.domainObject.AnswerJournalDO;
import com.kai.steering.data.service.entity.po.Answer;
import com.kai.steering.data.service.entity.po.AnswerJournal;
import com.kai.steering.data.service.mapper.AnswerJournalMapper;
import com.kai.steering.data.service.mapper.AnswerMapper;
import com.kai.steering.data.service.service.AnswerJournalService;
import com.kai.steering.data.service.service.AnswerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
@Slf4j
@Service
public class AnswerJournalServiceImpl extends BaseServiceImpl<AnswerJournalMapper, AnswerJournal> implements AnswerJournalService {

    @Override
    public AnswerJournalDO saveAnswerJournal(AnswerJournalDO answerJournalDO) {
        AnswerJournal answerJournal = new AnswerJournal(answerJournalDO);

        if (save(answerJournal)) {
            return new AnswerJournalDO(answerJournal);
        }

        return null;
    }

    @Override
    public boolean updateAnswerJournal(Serializable id, AnswerJournalDO answerJournalDO) {
        AnswerJournal byId = getById(id);
        if (byId==null||byId.getId()==null) {
            throw ReturnCodeExt.PARAMETER_CHECK.getException("对象[" + id + "]不存在");
        }
        answerJournalDO.setId(id.toString());
        AnswerJournal answerJournal = new AnswerJournal(answerJournalDO);
        return updateById(answerJournal);
    }

    @Override
    public boolean deleteAnswerJournal(Serializable id) {
        AnswerJournal byId = getById(id);
        if (byId==null||byId.getId()==null) {
            throw ReturnCodeExt.PARAMETER_CHECK.getException("对象[" + id + "]不存在");
        }
        return removeById(id);
    }
}
